- name: kube-state-metrics
  rules:
  - alert: DeploymentGenerationMismatch
    expr: max(kube_deployment_status_observed_generation != kube_deployment_metadata_generation) by (namespace, deployment)
    for: 15m
    labels:
      severity_level: "4"
    annotations:
      plk_protocol_version: "1"
      description: Observed deployment generation does not match expected one for
        deployment {{$labels.namespace}}/{{$labels.deployment}}
      summary: Deployment is outdated
  - alert: KubeStateMetricsDown
    expr: absent(up{job="kube-state-metrics"} == 1)
    for: 5m
    labels:
      severity_level: "3"
    annotations:
      plk_protocol_version: "1"
      plk_markup_format: markdown
      description: |-
        There are no metrics about cluster resources for 5 minutes.

        Most alerts an monitroing panels aren't working.

        To debug the problem:
        1. Check kube-state-metrics pods: `kubectl -n d8-monitoring describe pod -l app=kube-state-metrics`
        2. Check its logs: `kubectl -n d8-monitoring describe deploy kube-state-metrics`
      summary: >
        Kube-state-metrics is not working in the cluster.
  # kube_persistentvolume_is_local migration.
  # The patch was not generic enough, but it is used in many alerts/panels.
  # This recording rule is aimed to avoid rewriting them.
  - expr: |
      max by (instance, job, persistentvolume, scrape_endpoint, storageclass) (
          kube_persistentvolume_info{local_path=~".+"} or kube_persistentvolume_info{host_path=~".+"}
        or
          (kube_persistentvolume_info - 1)
      )
    record: kube_persistentvolume_is_local
